/var/folders/k5/1ngg2lrs0p51m_z5s1q72vv00000gn/T/ipykernel_58605/3067287871.py:1: DtypeWarning: Columns (106,113,125,126,129,131,134,142,143,156,157,158,165,166,169,176,177,181,182,185,186,190,192,202,207,221) have mixed types. Specify dtype option on import or set low_memory=False.
df_bevoelkerung = pd.read_csv(
Datatype Korrekturen durchführen, sodass danach nur noch Category oder float vorhanden ist: - interger in float verwandeln - / und - in 0-Werte verwandeln, da diese im engeren Sinne als 0 zählen - Zahlen in Klammern als normale Zahlen verwandeln
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LassoCV(cv=5, random_state=0)
0.0063775417634839085
Fit model
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
LinearRegression()
Migrationsquote
Name
Coefficient
0
Intercept
5.342
1
slope
-0.064
Christenquote
Name
Coefficient
0
Intercept
8.241
1
slope
-0.065
Singlequote
Name
Coefficient
0
Intercept
-12.168
1
slope
0.314
Multiple Regression
Name
Coefficient
0
Intercept
20.239
1
Migrationsquote2
-0.000
2
Christenquote
-0.064
3
Männerquote
-0.428
4
Akademikerquote
-0.147
5
Beamtenquote
0.044
6
Singlequote
0.203
Fit Model Lasso Regression
Lasso(alpha=0.0063775417634839085)
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
Lasso(alpha=0.0063775417634839085)
Name
Coefficient
0
Intercept
4.215
1
Migrationsquote2
-0.003
2
Christenquote
-1.350
3
Männerquote
-0.349
4
Akademikerquote
-0.812
5
Beamtenquote
0.062
6
Singlequote
0.591
Evaluation on test set
a
0
15
1
30
2
20
array([4.3892813 , 3.43630654, 4.07162304])
Migrationsquote2
1120
18.461538
810
15.162791
1339
3.671189
534
18.630933
514
14.435390
...
...
1263
21.283255
1281
10.962963
1209
12.860013
1007
22.473868
1404
5.213904
315 rows × 1 columns
0.027
0.382
0.121
0.636
0.024
0.38
0.118
0.629
4.708
2.991
4.254
1.762
2.17
1.729
2.063
1.327
1.686
1.296
1.492
1.004
Evaluation on test set Lasso Regression
0.635
0.628
1.767
1.329
1.004
Feature Importance Multiple Regression
coeff
name
0
0.000
Migrationsquote2
1
0.064
Christenquote
2
0.428
Männerquote
3
0.147
Akademikerquote
4
0.044
Beamtenquote
5
0.203
Singlequote
Feature Importance Lasso
coeff
name
0
0.003
Migrationsquote2
1
1.350
Christenquote
2
0.349
Männerquote
3
0.812
Akademikerquote
4
0.062
Beamtenquote
5
0.591
Singlequote
Save model
Save your model in the folder models/. Use a meaningful name and a timestamp.
ValueError: X has 1 features, but LinearRegression is expecting 6 features as input.
Conclusions
Um ein Verständnis für die Daten zu erhalten, beschreiben wir zuerst unsere bereinigte Datengrundlage, welche für die Anwendung der Modelle genutzt wird.
Das Histogramm “Christenquote” weist eine linksschiefe, multimodale Verteilung auf. Die “Männerquote” weist eine annähernd symetrische, unimodale Verteilung auf. Alle weiteren Variablen sind rechtsschief, unimodal verteilt.
Migrationsquote2
Christenquote
Männerquote
Akademikerquote
Beamtenquote
Singlequote
Arbeitslosenquote2
Migrationsquote2
1.000000
0.430310
-0.049660
0.093810
-0.014510
0.063220
-0.295450
Christenquote
0.430310
1.000000
0.153050
-0.253270
0.286860
-0.315040
-0.662740
Männerquote
-0.049660
0.153050
1.000000
-0.303060
-0.091700
-0.274020
-0.233030
Akademikerquote
0.093810
-0.253270
-0.303060
1.000000
0.273150
0.239260
-0.102600
Beamtenquote
-0.014510
0.286860
-0.091700
0.273150
1.000000
-0.039460
-0.256720
Singlequote
0.063220
-0.315040
-0.274020
0.239260
-0.039460
1.000000
0.444410
Arbeitslosenquote2
-0.295450
-0.662740
-0.233030
-0.102600
-0.256720
0.444410
1.000000
Die stärkste positive Korrelation, in dem untersuchten df_analyse_Gemeinde, zwischen Arbeitslosenquote und den Predictor Variables weist die Singlequote, mit r = +0.44441, auf. Die stärkste negative Korrelation mit der Arbeitslosenquote weist die Christenquote, mit r = -0.66274, auf. Die geringste Korrelation weist die “Akademikerquote”, mit r = -0.102600, auf.
Conclusion Models
Lineare Regression
Folgende Statistiken wurden mit der lineraren Regression für die folgenden Quoten ermittelt:
Statistik
Migrationsquote
Christenquote
Singlequote
0
R squared
0.027
0.382
0.121
1
R squared adj.
0.024
0.38
0.118
2
MSE
4.708
2.991
4.254
3
RMSE
2.17
1.729
2.063
4
MAE
1.686
1.296
1.492
Von diesen drei Modellen ist das Modell mit der Christenquote als Prädikator noch am Besten. Mit dem R squared zeigt sich trotzdem eine mäßige Güte des Models. Nur 38.2% der Variabilität der Arbeitslosigkeit wird hiermit erklärt.
Multiple Regression
Der R squared beträgt 0.636 und bedeutet eine mittlere Güte des Modells. Etwa 63.6 % der Variabilität der Arbeitslosigkeit wird durch die multiple Regression erklärt. Der adjusted R squared beträgt 0.629 und erklärt 62.9 % der Variabilität der Arbeitslosigkeit. Somit ist der adjusted R squared minimal schlechter als der R squared Wert.
Der mean sqaured error (1.762), root mean squared error (1.327) und der mean absolute error (1.004) ist niedriger als bei den Modellen der linearen Regression. Aus diesem Grund ist die multiple Regression der linearen Regression vorzuziehen.
Lasso Regression
Der R squared beträgt 0.635 und bedeutet eine mittlere Güte des Modells. Etwa 63.5 % der Variabilität der Arbeitslosigkeit wird durch die Lasso Regression erklärt. Der adjusted R squared beträgt 0.628 und erklärt 62.7 % der Variabilität der Arbeitslosigkeit. Somit ist der adjusted R squared minimal schlechter als der R squared Wert.
Der mean sqaured error (1.767), root mean squared error (1.329) und der mean absolute error (1.004) ist minimal niedriger als bei der multiplen Regression. Aus diesem Grund ist unterscheiden sich die Lasso und multiple Regression kaum.